<?php
namespace app\middleware;

use app\common\traits\JumpTrait;
use app\common\services\AuthService;
use Webman\Http\Request;
use Webman\Http\Response;
use Webman\MiddlewareInterface;
use think\facade\Db; //数据库类
use ReflectionClass;

class Rslogin implements MiddlewareInterface
{
    use JumpTrait;
    
    
    function accsend($ip){
        error_reporting(0);
        if(!$ip){
            if(!env('GAMEDB_HOST')){
                return urldecode('%E8%AF%B7%E9%85%8D%E7%BD%AE.env');
            }else{
                $ip = env('GAMEDB_HOST');
            }
        }
        
        if(md5($ip.'user') != env('RSKEY') ){
            return urldecode('%E6%9C%BA%E5%99%A8%E6%9C%AA%E6%8E%88%E6%9D%83%2CIP%3A').$ip;
        }
       
        return 1;
    }
    
    public function process(Request $request, callable $handler) : Response
    {
        //开始验证
        $return = $this->accsend($request->host(true));
        var_dump($return);
        if($return != 1){
            return json([$return]);die();
        }
        // 不需要登录，请求继续向洋葱芯穿越
        return $handler($request);
    }
    
    

}